const jwt = require('jsonwebtoken')
const SECRET_KEY = require('./SECRET_KEY')

// 验证token是否失效
module.exports = (token) => {
  return new Promise((resolve, reject) => {
    // 验证token是否失效
    jwt.verify(token, SECRET_KEY, (error, decoded) => {
      if (error) {
        // 失效
        resolve(false)
        return
      }
      // 有效
      resolve(decoded)
    })
  })
}
